﻿using System;
using System.Collections.Generic;
using System.Text;

using com.crawler.common;

namespace com.crawler.db.Interface
{
    public interface DataManager
    {
        /// <summary>
        /// 添加小说信息
        /// </summary>
        /// <param name="i_book"></param>
        /// <returns></returns>
        long AddBook(BookInfo i_book, string i_connect_string);

        /// <summary>
        /// 添加章节信息
        /// </summary>
        /// <param name="i_chapter"></param>
        /// <returns></returns>
        long AddChapter(ChapterInfo i_chapter, string i_connect_string,string i_table_name);

        /// <summary>
        /// 批量插入章节信息
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_book_name"></param>
        /// <param name="i_chapter_list"></param>
        /// <param name="i_connect_string"></param>
        /// <param name="i_table_name"></param>
        /// <returns></returns>
        int AddChapterList(long i_book_id, string i_book_name, List<ChapterInfo> i_chapter_list, string i_connect_string, string i_table_name,int i_site_id,string i_site_name);

        /// <summary>
        /// 获取某本小说的最后更新章节ID
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <returns></returns>
        long GetLastUpdateChapterId(long i_book_id, string i_connect_string,string i_table_name);

        /// <summary>
        /// 更新书籍最近跟新时间
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_last_update_chapter_id"></param>
        /// <param name="i_last_update_chapter_name"></param>
        /// <param name="i_last_update_time"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int UpdateBook(long i_book_id, string i_connect_string,string i_table_name,int i_chapter_count);

        /// <summary>
        /// 创建表结构
        /// </summary>
        /// <param name="i_table_name"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int CreateTable(string i_table_name, string i_connect_string);

        /// <summary>
        /// 获取需要更新的小说章节
        /// </summary>
        /// <returns></returns>
        List<BookInfo> GetUpdateBookList(string i_connect_string);

        /// <summary>
        /// 获取图书信息
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <returns></returns>
        BookInfo GetBookInfo(long i_book_id,string i_connect_string);

        /// <summary>
        /// 初始化数据库脚本
        /// </summary>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int InitDBScript(string i_connect_string);

        /// <summary>
        /// 获取站点图书信息
        /// </summary>
        /// <param name="i_book_name"></param>
        /// <param name="i_site_id"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        BookInfo GetBookInfoByName(string i_book_name, string i_connect_string);

          /// <summary>
        /// 初始化站点到数据库
        /// </summary>
        /// <param name="i_book_site_list"></param>
        /// <returns></returns>
        int InitBookSite(List<BookSiteInfo> i_book_site_list, string i_connect_string);

        
        /// <summary>
        /// 插入站点信息
        /// </summary>
        /// <param name="i_site_id"></param>
        /// <param name="i_site_name"></param>
        /// <param name="i_tb_name"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int InsertBookSite(int i_site_id, string i_site_name, string i_tb_name,string i_site_enconding,string i_chapter_content_reg,string i_chapter_content_filter, string i_connect_string);

         /// <summary>
        /// 获取小说信息
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        BookInfo GetBookInfoById(long i_book_id, string i_connect_string);

        /// <summary>
        /// 获取需要更新的小说队列
        /// </summary>
        /// <param name="i_site_list"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        Queue<SiteUrl> GetUpdateBook(List<BookSiteInfo> i_site_list,int i_page_index, string i_connect_string);

        /// <summary>
        /// 获取小说章节列表
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<ChapterInfo> GetChapterByBookId(long i_book_id, string i_connect_string);

         /// <summary>
        /// 更新小说下载状态
        /// </summary>
        /// <param name="i_chapter_id"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int UpdateChapter(long i_book_id, long i_chapter_id,string i_chapter_url,BookUrlInfo i_book_url, string i_connect_string);

         /// <summary>
        /// 添加热点排行榜小说
        /// </summary>
        /// <param name="i_book_name"></param>
        /// <param name="i_book_source"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        long AddTopBook(string i_book_name, Consts.BookSource i_book_source, string i_connect_string);

          /// <summary>
        /// 添加图书点击
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_connect_string"></param>
        void AddBookClick(long i_book_id, string i_connect_string);

        /// <summary>
        /// 获取从seo搜索的图书
        /// </summary>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<BookInfo> GetSEOBook(string i_connect_string);

        /// <summary>
        /// 获取需要更新的VIP图书
        /// </summary>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<BookInfo> GetVIPBook(string i_connect_string);

        /// <summary>
        /// 获取小说的章节地址列表
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<BookUrlInfo> GetBookUrlByBookId(long i_book_id, string i_connect_string);

          /// <summary>
        /// 添加小说URL
        /// </summary>
        /// <param name="i_book_url"></param>
        /// <returns></returns>
        int AddBookUrl(BookUrlInfo i_book_url, string i_connect_string);

        /// <summary>
        /// 更新小说封面地址
        /// </summary>
        /// <param name="i_book_id"></param>
        /// <param name="i_icon_url"></param>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        int UpdateBookUrl(long i_book_id, string i_icon_url, string i_connect_string);

        /// <summary>
        /// 获取小说列表
        /// </summary>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<BookUrlInfo> GetICONBookList(string i_connect_string);

        /// <summary>
        /// 获取需要更新小说章节的小说
        /// </summary>
        /// <param name="i_connect_string"></param>
        /// <returns></returns>
        List<BookInfo> GetSEOBookChapterContent(string i_connect_string);
    }
}
